package TenoriOn.UI
{
	import flash.display.GradientType;
	import flash.display.Sprite;
	import flash.geom.Matrix;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.utils.clearInterval;
	import flash.utils.setInterval;
	
	public class TextDisplay extends Sprite
	{
		[Embed(source="TenoriOn/Resources/lcd.ttf",fontName="lcd_font",mimeType="application/x-font-truetype",embedAsCFF="false")]
		private var ledFont:Class;
		
		private var fgText:TextField;
		
		private var _lines:Vector.<String>;
		
		public function TextDisplay()
		{
			super();
			
			var mat:Matrix=new Matrix();
			
			mat.createGradientBox(50,50,Math.PI/2)
			graphics.beginGradientFill(GradientType.LINEAR,[0xccdd00,0xbbbb00],[1,1],[0,255],mat);
			graphics.drawRoundRect(0,0,200,75,20,20);
			
			graphics.lineStyle(10);
			mat.createGradientBox(75,75,Math.PI/2);
			graphics.lineGradientStyle(GradientType.LINEAR,[0xc1c3c2,0xe7e8ec,0xc6cacd,0xe3dfde,0x979d9d,0x555259,0xa5a5ad],[1,1,1,1,1,1,1],[0,30,80,120,160,200,255],mat);
			
			mat.createGradientBox(75,75,Math.PI/2,75,-15);
			graphics.beginGradientFill(GradientType.LINEAR,[0xFFFFFF,0xFFFFFF,0xFFFFFF],[0.1,0.45,0],[0,150,151],mat);
			
			graphics.drawRoundRect(0,0,200,75,20,20);
			
			var bgText:TextField=new TextField();
			bgText.embedFonts=true;
			bgText.autoSize=TextFieldAutoSize.LEFT;
			bgText.alpha=0.2;
			bgText.defaultTextFormat=new TextFormat("lcd_font",15,0x000000);
			bgText.text="||||||||||||||||\r||||||||||||||||\r||||||||||||||||\r||||||||||||||||";
			bgText.x=(200-bgText.width)/2;
			bgText.y=(75-bgText.height)/2;
			bgText.selectable=false;
			addChild(bgText);
			
			_lines=new <String>["","","",""];
			_lines.fixed=true;
			
			fgText=new TextField();
			fgText.embedFonts=true;
			fgText.autoSize=TextFieldAutoSize.LEFT;
			fgText.alpha=0.7;
			fgText.defaultTextFormat=new TextFormat("lcd_font",15,0x000000);
			fgText.text=_lines.join("\r");
			fgText.x=bgText.x;
			fgText.y=bgText.y;
			fgText.selectable=false;
			addChild(fgText);
			
			redraw();
		}
		
		public function setText(line0:String="",line1:String="",line2:String="",line3:String=""):void{
			_lines[0]=line0;
			_lines[1]=line1;
			_lines[2]=line2;
			_lines[3]=line3;
			redraw();
		}
		
		public function setLine(line:int,text:String):void{
			_lines[line]=text;
			redraw();
		}
		
		private function redraw():void{
			var textStr:String="";
			for (var l:*=0; l<4; l++){
				textStr+=_lines[l].substr(0,16)+"\r";
			}
			fgText.text=textStr;
		}
	}
}